package com.baizhi.service.impl;

import com.baizhi.entity.Brand;
import com.baizhi.entity.Category;
import com.baizhi.mapper.BrandMapper;
import com.baizhi.service.IBrandService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author longyang
 * @since 2022-01-19
 */
@Service
public class BrandServiceImpl extends ServiceImpl<BrandMapper, Brand> implements IBrandService {
    @Autowired
    private BrandMapper brandmapper;
    @Override
    public PageInfo<Brand> selectBrandByCategoryId(Integer categoryId,int pageNum,int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Brand> brands = brandmapper.selectBrandByCategoryId(categoryId);
        PageInfo<Brand> bookPageInfo = new PageInfo<Brand>(brands);
        return bookPageInfo;
    }

    @Override
    public Integer addBrand(Brand brand) {
        int insert = brandmapper.insert(brand);
        return insert;
    }

    @Override
    public Integer deleteBrand(Integer brandId) {
        return brandmapper.deleteById(brandId);
    }

    @Override
    public Brand selectBrandById(Integer brandId) {
        //条件构造器：用于构建sql条件
        QueryWrapper<Category> queryWrapper = new QueryWrapper<>();
        //获取角色所有权限id且查询权限表内的对应id信息并返回
        //获取角色所有权限id且查询权限表内的对应id信息并返回
        queryWrapper.eq("brand_id",brandId);
        return brandmapper.selectById(brandId);
    }

    @Override
    public Integer updateBrand(Brand brand) {
        return brandmapper.updateById(brand);
    }
}
